﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace YAMN_Cinemas.Presentation
{
    public partial class LoginForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string username = txt_UserID.Text;
            string password = txt_Password.Text;
            string admin="Admin";
            string user="User";
            bool ans = Membership.ValidateUser(username, password);
            if (ans == true)
            {
               if(Roles.IsUserInRole(username,admin))
               {
                   FormsAuthentication.RedirectFromLoginPage(username, chkPersistCookie.Checked);
                   Response.Redirect("Admin_Home.aspx?username=" + username);


               }
               else if(Roles.IsUserInRole(username,user))
               {
                   FormsAuthentication.RedirectFromLoginPage(username, chkPersistCookie.Checked);
                   Response.Redirect("WelcomePage1.aspx?username="+username);

               }
            }
            else if (ans == false)
            {
                lbl_Status.Visible = true;
                lbl_Status.Text = "Please try again with a valid Username and Passowrd";


            }
            else
            {
                lbl_Status.Text = "You dont have the aAministrator rights to access this page";
            }
            
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("LoginForm.aspx");

        }
    }
}